package com.cci.kangdao.dao;

import com.cci.kangdao.cipFleet.dto.request.CipFleetAndEsnRequest;
import com.cci.kangdao.cipFleet.dto.response.CipFleetResponse;
import com.cci.kangdao.cipFleet.dto.response.CipVehicleResponse;
import com.cci.kangdao.cipFleet.entity.CipFleetT;
import com.cci.kangdao.cipFleet.entity.CipFleetWhiteT;
import com.cci.kangdao.cipFleet.entity.CipVehicleT;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface CipFleetMapper {

    CipFleetT getFleetById(@Param("id") Long id, @Param("cipFleetId") String cipFleetId);

    List<CipFleetAndEsnRequest> appFleetHistory();

    List<Long> appFleetUseridList();
    //获取车辆信息
    List<CipVehicleResponse> getVehicleListByFleetId(@Param("fleetId") Long fleetId);

    //获取车队信息
    List<CipFleetResponse> getFleetByUserId(@Param("userId") Long userId, @Param("type") Integer type);

    //获取车辆信息
    List<CipVehicleResponse> getVehicleByList(@Param("userId") Long userId,@Param("fleetIdList") List<Long> fleetIdList);
    //无车队车辆
    List<CipVehicleResponse> getNoFleetByList(@Param("userId") Long userId);
    //是否白名单
    int isFleetWhite(@Param("userId") Long userId);

    //用户车辆信息
    CipVehicleT getUserESN(@Param("userId") Long userId,@Param("esn") String esn);
    //车辆验重
    Long vehicleCheck(@Param("fleetId") Long fleetId,@Param("esn") String esn);

    int getFleetCount();
    //根据userid    获取车队的数量
    int getFleetCountByUserId(Long userId);

    //车队验重
    Long fleetCheck(@Param("userId") Long userId,@Param("fleetCode") String fleetCode);

    //添加车队信息
    int insertFleet(CipFleetT cipFleetT);

    //修改车队信息
    int updateFleet(CipFleetT cipFleetT);

    //删除车队信息
    int deleteFleet(@Param("fleetId") Long fleetId,@Param("userId") Long userId,@Param("time") String time);
    //陕康云删除车队
    int deleteShanKangFleetByUserId(@Param("userId") Long userId,@Param("time") String time);

    //添加车辆信息
    int insertVehicle(CipVehicleT cipVehicleT);

    int updateByServiceChannel(@Param("serviceChannel") String serviceChannel,@Param("userId")Long userId);

    //修改车辆信息
    int updateVehicle(CipVehicleT cipVehicleT);

    //删除车辆信息
    int deleteVehicle(@Param("fleetId") Long fleetId, @Param("userId") Long userId, @Param("time") String time);

    //添加白名单
    int insertWhite(CipFleetWhiteT cipFleetWhiteT);

    /**
     * @param userId 用户id
     * @param type   1 和 null  是app端创建的车队      2 是老友会创建的车队
     * @return
     */
    List<Map<String, Object>> getFleetListByUserId(@Param("userId") Long userId, @Param("externalUserId") String externalUserId, @Param("type") Integer type);

    /**
     * @param userId 用户id
     * @return
     */
    List<CipFleetAndEsnRequest> getFleetsByUserId(@Param("userId") Long userId);


    List<CipFleetT> getFleetModelListByUserId(@Param("userId") Long userId);


    //车队名称验重
    int fleetNameCheck(@Param("userId") Long userId,@Param("externalUserId") String externalUserId, @Param("fleetName") String fleetName, @Param("type") Integer type);

    @Update("update Cip_Fleet_T set Flag = #{flag},Deleter = #{userId},DeleteTime = #{updateTime} where Id  = #{fleetId}")
    int deleteFleetById(@Param("flag") int flag, @Param("userId") Long userId, @Param("updateTime") String updateTime, @Param("fleetId") Long fleetId);

    List<CipVehicleResponse> getVehicleByListExternal(@Param("userId") Long userId, @Param("fleetIdList") List<Long> idList, @Param("type") Integer type);

    @Update("update Cip_Fleet_T set CIPFleetId = #{cipFleetId} where Id = #{fleetId}")
    int updateCIPFleetIdById(@Param("cipFleetId") String CIPFleetId, @Param("fleetId") Long fleetId);

    //删除车队信息
    int deleteFleetByUserIdAndNameAndChannel(@Param("userId") Long userId,@Param("time") String time,@Param("fleetName") String fleetName,@Param("serviceChannel") String serviceChannel);

    int getListByUserIdAndFleet(@Param("userIdAndFleetList") List<String> userIdAndFleetList);
    List<String> getFleetLabel(@Param("id") Long id);

    List<CipFleetT> getListByUserId(@Param("userId") Long userId);

}
